<template>
    <div>
        <tool-bar nav="" title='Json转换为模型类'></tool-bar>
        <el-row :gutter="20" class="grid">
            <el-col :span="10">
                <el-input type="textarea" v-model="$data.txt1"></el-input>
            </el-col>
            <el-col :span="3" class="op_column">

                <kv label="默认值">
                    <el-switch v-model="$data.defValue"></el-switch>
                </kv>
                <kv label="static(java)">
                    <el-switch v-model="$data.staticClass"></el-switch>
                </kv>
                <kv label="可空(kotlin)">
                    <el-switch v-model="$data.nullable"></el-switch>
                </kv>
                <el-button @click="ok_click('java','@data')">Java-@Data</el-button>
                <el-button @click="ok_click('java','map')">Java-Map</el-button>
                <el-button @click="ok_click('java','public')">Java-public</el-button>
                <el-button @click="ok_click('kotlin')">Kotlin</el-button>

            </el-col>
            <el-col :span="10">
                <el-input type="textarea" v-model="$data.txt2"></el-input>
            </el-col>
        </el-row>
    </div>
</template>
<script setup>
/**
 * Created by CodeGenerator
 */



defineOptions({
    name: "json-class",
    inheritAttrs: true,
});

//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();


//定义data
const $data = reactive({
    txt1: "",
    txt2: "",
    defValue: false,
    nullable: true,
    staticClass: false,
    embed: []
});


const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue", "loaded"]);


const ok_click = function (lang, param) {
    jv.$saveData("txt1", $data.txt1);
    var json;
    try{
        json = JSON.parse($data.txt1);
    } catch (e){
        json = eval( "()=> { return " + $data.txt1 + "}" )()
    }


    $data.txt2 = jv.dev.json2Pojo("Root", json, lang, param, $data.staticClass, $data.defValue, $data.nullable, 0);
};

onMounted(function () {
    jv.$loadData("txt1", v => $data.txt1 = v);
})


</script>

<style lang="scss" scoped>

.grid {
    position: relative;
    margin-left: 20px !important;
    margin-top: 20px !important;
    display: flex;

    ::v-deep(textarea), ::v-deep(.el-col), ::v-deep(.el-textarea) {
        min-height: 60vh !important;
        height: 70vh;
    }
}

.op_column {
    padding-top: 150px;
    padding-bottom: 150px;
    display: flex;
    flex-wrap: wrap;
    place-content: center;
    align-content: space-around;
    position: relative;
    height: 100%;


    button {
        display: block;
        margin: 10px 6px;
    }

}
</style>